package zuoye.考试1;

import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

//5. 输入5个同学的姓名和成绩，求出最高分，最低分和平均分，以及每个人的成绩与平均分的差值。
//最后，按分数从高到低排序。
public class Demo5 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("请输入学生的名字和成绩");
        String name = input.next();
        int a = input.nextInt();
        String name1 = input.next();
        int b = input.nextInt();
        String name2 = input.next();
        int c = input.nextInt();
        String name3 = input.next();
        int d = input.nextInt();
        String name4 = input.next();
        int e = input.nextInt();

        System.out.println(name + " " + a);
        System.out.println(name1 + " " + b);
        System.out.println(name2 + " " + c);
        System.out.println(name3 + " " + d);
        System.out.println(name4 + " " + e);
        input.close();

        int[] grade = {a, b, c, d, e};

        int min, max;
        min = max = grade[0];
        for (int i = 0; i < grade.length; i++) {
            if (grade[i] > max)   // 判断最大值
                max = grade[i];
            if (grade[i] < min)   // 判断最小值
                min = grade[i];
        }
        System.out.println("最大值为：" + max);
        System.out.println("最小值为：" + min);
        int total = a + b + c + d + e;
        int value = total / grade.length;
        System.out.println("总分为：" + total);
        System.out.println("平均分为：" + value);
        int poor = 0;
        for (int i = 0; i < grade.length; i++) {
            if (grade[i] > value) {
                poor = grade[i] - value;
                System.out.println(grade[i] + "比平均分多了" + poor);
            }
            if (grade[i] < value) {
                poor = value - grade[i];
                System.out.println(grade[i] + "比平均分少了" + poor);
            }
        }

        int temp = 0;
        for (int i = 0; i < grade.length - 1; i++) {
            for (int j = 0; j < grade.length - 1 - i; j++) {
                if (grade[j] < grade[j + 1]) {
                    temp = grade[j];
                    grade[j] = grade[j + 1];
                    grade[j + 1] = temp;
                }
            }
        }
        System.out.println("排序结果");
        for (int i = 0; i < grade.length; i++) {
            System.out.print(grade[i] + " ");
        }
        System.out.println("====================");
        Arrays.sort(grade);
        for (int i : grade){
            System.out.print(i+" ");
        }

        System.out.println("===================");
        Integer[] arr={a, b, c, d, e};
        //注意必须要用Integer来定义数组，不能用int，因为int没法看成对象，
        //所以要用int的封装类Integer。不然sort方法报错
        Arrays.sort(arr,new Comparator<Integer>(){
            public int compare(Integer a,Integer b){
                return b-a;
            }
        });
        for(int i:arr){
            System.out.print(i+" ");
        }
    }

}
//王 50 傅 20 张 30 李 20 孙 100